<%-- 
    Document   : add
    Created on : 6-dec-2009, 15:23:59
    Author     : Simon
--%>

<%-- ${pageContext.request.contextPath} --%>
<%@include file="../header.jsp" %>

<h1>Add a patient</h1>

<div class="flash info">
    If you enter a social security number of a patient already registered with other doctors and move to another input field,
    all the other fields will be automatically filled in and you can edit these and afterwards choose to add this patient to your list.
    It is not possible to change these patients username or password.
</div>

<c:if test="${!empty flash}">
    <div class="flash error">${flash}</div>
</c:if>

<form action="${pageContext.request.contextPath}/gp/patient/saveadd.jsp" method="post">
    <table>
        <tr>
            <td>
                <label for="SSN">Social security number</label>
            </td>
            <td>
                <input type="text" name="socialSecurityNumber" id="SSN" value="${patient.socialSecurityNumber}"/>
                <input type="hidden" name="id" id="id" value="${patient.id}" />
            </td>
        </tr>
        <tr>
            <td>
                <label for="lastname">Surname</label>
            </td>
            <td>
                <input id="lastname" name="surname" type="text" value="${patient.surname}"/>
            </td>
        </tr>
        <tr>
            <td>Firstname</td>
            <td>
                <input type="text" name="firstname" id="firstname" value="${patient.firstname}"/>
            </td>
        </tr>
        <tr>
            <td>Date of birth</td>
            <td>
                <fmt:formatDate value="${patient.birthDate}" var="birth" pattern="d/m/yyyy" />
                <input type="text" name="birthDate" id="birth" value="${birth}" />
            </td>
        </tr>
        <tr>
            <td>Bloodgroup</td>
            <td>
                <input type="text" name="bloodgroup" id="bloodgroup" value="${patient.bloodgroup}"/>
            </td>
        </tr>
        <tr id="username">
            <td>Username</td>
            <td>
                <input type="text" name="username" value="${patient.username}"/>
            </td>
        </tr>
        <tr id="password">
            <td>Password</td>
            <td>
                <input type="text" name="password" />
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="submit" name="submit" value="Add" />
                <input type="reset" name="submit" value="Reset" id="reset"/>
            </td>
        </tr>
    </table>
</form>

<script type="text/javascript">
    $(document).ready(function() {


        $("#birth").datepicker({dateFormat : 'd/m/yy'});

        if ($("#id").val() != "") {
            $("#password").hide();
            $("#password").val("");
            $("#username").hide();
            $("#username").val("");
        }

        $("#SSN").blur(function() {
            $("#password").show();
            $("#username").show();
            $("#id").val("");
            var jso = {s:true,p:{p:"yes"}};
            $.getJSON("${pageContext.request.contextPath}/gp/patient/search", {ssn : $("#SSN").val()}, function(data, status) {
                if (data.success) {
                    $("#id").val(data.patient.id == null ? 0 : data.patient.id);
                    $("#lastname").val(check_null(data.patient.lastname));
                    $("#firstname").val(check_null(data.patient.firstname));
                    $("#birth").val(check_null(data.patient.birthdate));
                    $("#bloodgroup").val(check_null(data.patient.bloodgroup));
                    $("#id").val(data.patient.id);
                    $("#password").hide();
                    $("#password").val("");
                    $("#username").hide();
                    $("#username").val("");
                }
            });
        });
    $("#reset").click(function() {
        $("#password").show();
        $("#username").show();
    });

    function check_null(data) {
        if (data == null || data == "null")
            return "";
        return data;
    }

});
</script>

<%@include file="../footer.jsp" %>
